using UnityEngine;
using Voodoo.Pattern;

public class Control : MonoBehaviour
{
	private MoveDirection _joy;

	private Rigidbody _head;

	[SerializeField]
	private float _speedKf = 2f;

	private void Awake()
	{
		SingletonMB<GameManager>.Instance.Control = this;
	}

	private void Start()
	{
		Physics.IgnoreLayerCollision(6, 6);
	}

	public void SetHead(Rigidbody h)
	{
		_head = h;
	}

	private void FixedUpdate()
	{
		if (!(_head != null))
		{
			return;
		}
		if (Preloader.ABTestConfig.MovementSpeedMultiplier > 1f)
		{
			_head.velocity = new Vector3(_joy.Direction.x * _speedKf * Preloader.ABTestConfig.MovementSpeedMultiplier, _joy.Direction.y * _speedKf * Preloader.ABTestConfig.MovementSpeedMultiplier, 0f);
		}
		else
		{
			if (_head.isKinematic)
			{
				return;
			}
			if (SingletonMB<GameManager>.Instance.CanMove)
			{
				if (Singleton<InputController>.Instance.MoveVector != Vector3.zero || Singleton<InputController>.Instance.RightPressed || Singleton<InputController>.Instance.LeftPressed || Singleton<InputController>.Instance.DownPressed || Singleton<InputController>.Instance.UpPressed)
				{
					int num = (Singleton<InputController>.Instance.RightPressed ? 1 : (Singleton<InputController>.Instance.LeftPressed ? (-1) : 0));
					int num2 = (Singleton<InputController>.Instance.UpPressed ? 1 : (Singleton<InputController>.Instance.DownPressed ? (-1) : 0));
					Vector3 normalized = (new Vector3(num, num2, 0f) + Singleton<InputController>.Instance.MoveVector).normalized;
					_head.velocity = normalized * _speedKf;
				}
				else
				{
					_head.velocity = new Vector3(_joy.Direction.x * _speedKf, _joy.Direction.y * _speedKf, 0f);
				}
			}
			else
			{
				_head.velocity = Vector3.zero;
			}
		}
	}

	internal void ReplaceJoystick(MoveDirection joystick)
	{
		_joy = joystick;
	}
}
